/*
 * @ : Copyright (c) 2021 Phytium Information Technology, Inc. 
 *  
 * SPDX-License-Identifier: Apache-2.0.
 * 
 * @Date: 2021-06-25 14:31:02
 * @LastEditTime: 2021-09-02 10:50:49
 * @Description:  This files is for 
 * 
 * @Modify History: 
 *  Ver   Who        Date         Changes
 * ----- ------     --------    --------------------------------------
 */

#ifndef __INTERRUPT_H__
#define __INTERRUPT_H__

#include "ft_types.h"

/*
 * Interrupt handler definition
 */
typedef void (*IrqHandler)(s32 vector, void *param);

struct IrqDesc
{
        IrqHandler handler;
        void *param;
};

#define INT_IRQ 0x00
#define INT_FIQ 0x01

#define IRQ_MODE_TRIG_LEVEL (0x00) /* Trigger: level triggered interrupt */
#define IRQ_MODE_TRIG_EDGE (0x01)  /* Trigger: edge triggered interrupt */

void rt_hw_vector_init(void);

void InterruptInit(u32 gic_dist_base, u32 gic_irq_start);
void InterruptMask(int vector);
void InterruptUmask(int vector);

int InterruptGetIrq(void);
void InterruptAck(int vector);

void InterruptSetTargetCpus(int vector, unsigned int cpu_mask);
unsigned int InterruptGetTargetCpus(int vector);

void InterruptSetTrigerMode(int vector, unsigned int mode);
unsigned int InterruptGetTrigerMode(int vector);

void InterruptSetPending(int vector);
unsigned int InterruptGetPending(int vector);
void InterruptClearPending(int vector);

void InterruptSetPriority(int vector, unsigned int priority);
unsigned int InterruptGetPriority(int vector);

void InterruptSetPriorityMask(unsigned int priority);
unsigned int InterruptGetPriorityMask(void);

int InterruptSetPriorGroupBits(unsigned int bits);
unsigned int InterruptGetPriorGroupBits(void);

IrqHandler InterruptInstall(int vector, IrqHandler handler,
                            void *param, const char *name);


void IpiSend(int ipi_vector, unsigned int cpu_mask);
void IpiHandlerInstall(int ipi_vector, IrqHandler ipi_isr_handler);

void InterruptEarlyInit(void) ;

#endif
